package main

import (
	"github.com/gookit/goutil/strutil"
	"os"
	"snc/util"
	"strings"
)

func main() {
	args := os.Args
	if len(args) < 3 {
		println("参数不足！")
		return
	}
	bts, err := os.ReadFile(args[1])
	if err != nil {
		println("读取文件失败，请检查文件是否存在！")
		return
	}
	mas := strutil.Split(string(bts), "\n")
	buff := strings.Builder{}
	tm := util.ToInt(args[2])
	for _, m := range mas {
		for i := 0; i < tm; i++ {
			buff.WriteString(m)
			buff.WriteByte('\n')
		}
	}
	var outPath string
	if len(args) > 3 {
		outPath = args[3]
	} else {
		idx := strings.LastIndexAny(args[1], `.`)
		if idx < 0 {
			idx = len(args[1])
		}
		outPath = args[1][0:idx] + "_X" + util.ToStr(tm) + ".txt"
	}
	os.WriteFile(outPath, []byte(strings.TrimSpace(buff.String())), 666)
}
